<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>四月栈-归档</title>
    <meta name="description" content="本页面是对网站博客的日期归档">
    <div th:replace="_fragments::basicrefrence"></div>
</head>


<!--网页主体-->
<body>

    <!--网页头-->
    <nav th:replace="_fragments::guesthead"></nav>



    <div class="m-tenDistance">
        <div class="ui container">
            <!--头部-->
            <div class="ui top segment ">
                <div class="ui two column grid">
                    <div class="column">
                        <h3 class="ui teal header">全部</h3>
                    </div>
                    <div class="right aligned column">
                        <h3 class="item">共 x 个</h3>
                    </div>
                </div>
            </div>

            <div id="archivesDiv"></div>

            <!--主体内容-->
            <div th:each="dateAndBlog:${blogMap}">
                <h1 class="ui center aligned header" th:text="${dateAndBlog.key}"></h1>
                <div class="ui fluid vertical menu" th:each="blog:${dateAndBlog.value}">
                    <a th:href="@{blog(id=${blog.id})}" target="_blank" class="item">
                        <span>
                            <i class="ui mini circle icon"></i><span th:text="${blog.title}"></span>
                            <div class="ui teal basic label" th:text="${#dates.format(blog.createDate,'yyyy-MM-dd')}"></div>
                        </span>
                        <div class="ui large orange basic label" th:text="${blog.tag}==1?'原创':'搬运'"></div>
                    </a>
                </div>
            </div>


        </div>
    </div>


    <footer th:replace="_fragments::guestfoot"></footer>


</body>

<script type="text/javascript">
    var archivesDiv = $('#archivesDiv')
    $.ajax({
        url:"/getArchives",
        type:"get",
        success:function (resp) {
            if (resp.code === 0) {
                archivesDiv.append("发生了错误，没有查询到博客归档");
            }else{
                let archivesMap = resp.data;
                let keyArray = new Array();
                let index = 0;
                $.each(archivesMap,function(key,archives) {
                    keyArray[index++] = key;
                });
                keyArray.sort((a,b)=>{return b-a});
                for(let key of keyArray) {
                    let content = "<div>\n<h1 class=\"ui center aligned header\" > " + key + "</h1>\n";
                    for(let archive of archivesMap[key]) {
                        let archiveCreateDate = new Date(archive.createDate);
                        content += "<div class=\"ui fluid vertical menu\">" +
                            "<a href=\"/blog?id=" + archive.id + "\" target=\"_blank\" class=\"item\">" +
                            " <span>\n" +
                            "<i class=\"ui mini circle icon\"></i><span>" + archive.title + "</span>\n" +
                            "<div class=\"ui teal basic label\"> " +
                            archiveCreateDate.getFullYear() + "-" + (archiveCreateDate.getMonth()+1) + "-" + archiveCreateDate.getDate()
                            + " </div>\n" +
                            "</span>" +
                            "<div class=\"ui large orange basic label\">" + (archive.tag===1?'原创':'搬运') + "</div></a></div></div>";
                    }
                    archivesDiv.append(content);
                }
            }
        }
    })
</script>


</html>